<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
global $data;

class Panel extends CI_Controller {

    public function __construct() {
        parent::__construct();
        //redireccion segura
        if ($this->session->userdata('access') != 'grant') {
            redirect(base_url());
        }
        global $data;
        $data['responsableNombre'] = $this->session->userdata('responsableNombre');
        $data['place'] = 'panel';
        $this->stats();
        $this->output->enable_profiler(FALSE);
    }

    public function index() {
        //redireccion segura
        if ($this->session->userdata('access') != 'grant') {
            redirect(base_url());
        }
        //termina redirecion
        global $data;
        $data['colaboradores_por_carrera'] = $this->colaboradores_carrera();
        $data['colaboradores_por_rol'] = $this->colaboradores_rol();
        $this->load->view('template/header', $data);
        $this->load->view('template/sidebar');
        $this->load->view('panel/content');
        $this->load->view('template/footer');
    }

    //cerrar session
    public function out() {
        //termina redirecion
        $this->session->sess_destroy();

        redirect(base_url());
    }

    public function stats() {
        global $data;
        $data['acceso'] = $this->ciempies_model->lista_accesos();
        $data['tcolab'] = $this->ciempies_model->get_total('COLABORADOR');
        $data['ttutorial'] = $this->ciempies_model->get_total('TUTORIAL');
        $data['therramienta'] = $this->ciempies_model->get_total('HERRAMIENTA');
        $data['tuso_herramienta'] = $this->ciempies_model->get_total('uso_herramienta');
        $data['tvisita'] = $this->ciempies_model->get_total('visita');
    }

    public function colaboradores_carrera() {
        $col = $this->ciempies_model->colaboradores_por_carrera();
        $d = '';
        foreach ($col as $v) {
            $d.="{Carrera: '$v->carrera',Porcentaje: $v->porcentaje},";
        }
        $d = trim($d, ',');
        return $d;
    }

    public function colaboradores_rol() {
        $col = $this->ciempies_model->colaboradores_por_rol();
        $d = '';
        foreach ($col as $v) {
            $d.="{Rol: '$v->rol',Porcentaje: $v->porcentaje},";
        }
        $d = trim($d, ',');
        return $d;
    }

}
